package com.compass.doctor.ui.chat.attachment

import com.compass.doctor.R
import com.compass.framework.constant.PRESCRIPTION_CODE
import com.compass.framework.model.Drug
import com.compass.framework.model.MessageBody
import com.compass.framework.utils.getStringFromResource
import com.netease.yunxin.kit.corekit.im.custom.CustomAttachment
import org.json.JSONObject

/**
 * Description： 处方单消息
 * Date:2024/1/19 10:17
 */
class PrescriptionAttachment : CustomAttachment(PRESCRIPTION_CODE) {
    private var id: String? = null //处方id
    private var drugs: String? = null //json
    private var diagnosisName: String? = null//诊断
    private var price: Long? = null //药品费用


    //重写数据解析方法，这里面数据以JSONObject格式进行传输，所以您可以制定自己的数据格式。
    //这个示例表示，自定义数据格式为{"customer_message_key":"我是一个自定义消息"}
    override fun packData(): JSONObject {
        var data = JSONObject()
        data.put("id", id)
        data.put("drugs", drugs)
        data.put("diagnosisName", diagnosisName)
        data.put("price", price)
        return data
    }


    override fun parseData(jsonObject: JSONObject?) {
        // 从接收到的消息内容中解析您的数据
        jsonObject?.let {
            this.id = jsonObject.getString("id")
            this.drugs = jsonObject.getString("drugs")
            this.diagnosisName = jsonObject.getString("diagnosisName")
            this.price = jsonObject.getLong("price")
        }

    }


    /**
     * 设置处方单
     */
    fun setPrescriptionData(diagnosisName: String, price: Long,drugs: String, id:String) {
        this.id = id;
        this.price = price;
        this.diagnosisName = diagnosisName;
        this.drugs = drugs;

    }


    override fun getContent(): String? {
        return getStringFromResource(R.string.attachment_prescription_msg)
    }


    fun getRxId(): String? {
        return id;
    }

    fun getPrice(): Long? {
        return price;
    }

    fun getDrugs(): String? {
        return drugs;
    }

    fun getDescribe(): String? {
        return diagnosisName;
    }


}